
pipe_check_dict = {
    "build": "编译构建",
    "ut": "UT测试",
    "it": "IT测试",
    "vc": "版本校验",
    "ipmi": "ipmi修改",
    "dependency": "依赖校验",
    "line": "修改行数检查",
    "model_check": "模型检查",
    "header": "header文件检查",
    "coverage": "覆盖率检查",
    "smoke_test": "smoke测试",
    "sca": "sca检查",
}

class STATUS_ICON:
    SUCCEEDED = "&#9989;"
    WARNING = "&#x26A0;&#xFE0F;"
    FAILED = "&#10060;"
    NA = "N/A"


class STATUS_TEXT:
    SUCCEEDED = "SUCCESS"
    WARNING = "WARNING"
    FAILED = "FAILED"
    NA = "N/A"


class PIPELINE_STATUS:
    COMPLETED = "COMPLETED"
    PASS = "PASS"
    WARNING = "WARNING"
    NA = "N/A"
    UNDEFINDED = "__not__definded__"
    VALID_STATUS = [COMPLETED, WARNING, PASS]

    @classmethod
    def is_valid(cls, status):
        return status in cls.VALID_STATUS

    @classmethod
    def is_succ_status(cls, status):
        return status in [cls.COMPLETED, cls.WARNING]


class PIPELINE_CONFIG:
    DEFAULT_CONFIG = {
        PIPELINE_STATUS.COMPLETED: STATUS_ICON.SUCCEEDED + STATUS_TEXT.SUCCEEDED,
        PIPELINE_STATUS.PASS: STATUS_ICON.SUCCEEDED + STATUS_TEXT.SUCCEEDED,
        PIPELINE_STATUS.WARNING: STATUS_ICON.WARNING + STATUS_TEXT.WARNING,
        PIPELINE_STATUS.UNDEFINDED: STATUS_ICON.FAILED + STATUS_TEXT.FAILED
    }

    LOG_DEFAULT_CONFIG = {
        PIPELINE_STATUS.COMPLETED: STATUS_ICON.SUCCEEDED,
        PIPELINE_STATUS.PASS: STATUS_ICON.SUCCEEDED,
        PIPELINE_STATUS.WARNING:STATUS_ICON.WARNING,
        PIPELINE_STATUS.UNDEFINDED: STATUS_ICON.NA
    }

    # 这里定义例外的情况，比如 有的 COMPLETED 需要配置 WARNING
    CKECK_CONFIG = {
        'scan': {},
        'build': {},
        'it': {},
        'ut': {},
        'version_check': {},
        'ipmi_check': {
            PIPELINE_STATUS.UNDEFINDED: STATUS_ICON.WARNING + STATUS_TEXT.WARNING
        },
        'dependency_check': {},
        'line_limit_check': {
            PIPELINE_STATUS.UNDEFINDED: STATUS_ICON.WARNING + STATUS_TEXT.WARNING
        },
        'model_check': {},
        'smoke_test': {}
    }

    LOG_CHECK_CONFIG = {
        'scan': {},
        'build': {},
        'it': {},
        'ut': {},
        'version_check': {},
        'ipmi_check': {},
        'dependency_check': {},
        'line_limit_check': {},
        'model_check': {},
        'smoke_test': {}
    }

    @classmethod
    def get_status_icon(cls, check_name, status):
        if not PIPELINE_STATUS.is_valid(status):
            status = PIPELINE_STATUS.UNDEFINDED
        return cls.CKECK_CONFIG.get(check_name, {}).get(status, cls.DEFAULT_CONFIG[status])

    @classmethod
    def get_status(cls, check_name, status):
        if not PIPELINE_STATUS.is_valid(status):
            status = PIPELINE_STATUS.UNDEFINDED
        return cls.LOG_CKECK_CONFIG.get(check_name, {}).get(status, cls.LOG_DEFAULT_CONFIG[status])